package com.agileai.bpm.domain.define;

import java.io.Serializable;
import java.util.HashMap;

import org.codehaus.jackson.map.ObjectMapper;

import com.agileai.util.StringUtil;

public class Properties 
	extends HashMap<String,HashMap<String,String>> implements Serializable{
	private static final long serialVersionUID = -7116650503059819693L;

	public String toString(){
		String jsonString = null;
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			jsonString = objectMapper.writeValueAsString(this);				
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonString;
	}
	
	public static Properties fromString(String text){
		Properties result = null;
		if (!StringUtil.isNullOrEmpty(text)){
			ObjectMapper objectMapper = new ObjectMapper();
			try {
				result = objectMapper.readValue(text, Properties.class);			
			} catch (Exception e) {
				e.printStackTrace();
			}			
		}else{
			result = new Properties();
		}
		return result;
	}
}
